package com.aaron.platform.dao;

import java.io.Serializable;
import java.util.List;

import org.hibernate.criterion.DetachedCriteria;

/**
 * generic dao interface
 * @author mac
 * @param <T> class type
 * @param <ID> identity type
 */
public interface IGenericDAO<T, ID extends Serializable> {

    /**
     * find a entity by identity
     * @param id identity
     * @return entity
     */
    public T findById(ID id);

    /**
     * find all entity of T class type
     * @return entity list
     */
    public List<T> FindAll();

    /**
     * find all entity of T class type by page
     * @param pageSize 分页大小
     * @param statIndex 开始索引
     * @return PageInfo 分页信息
     */
    public PageInfo FindAllByPage(int statIndex, int pageSize);

    /**
     * find a entity by unique key
     * @param keyName
     * @param key
     * @return
     * @throws ObjectNotFoundException
     */
    public T findByUniqueKey(String keyName, Serializable key);

    /**
     * save a entity
     * @param entity entity to save
     */
    public void save(T entity);

    /**
     * save a entity
     * @param entity entity to save
     */
    public void saveOrUpdate(T entity);

    /**
     * save or update a list of entities
     * @param entities entity list
     */
    public void saveOrUpdateAll(List<T> entities);

    /**
     * update a entity
     * @param entity entity to update
     */
    public void update(T entity);

    /**
     * merge a entity
     * @param entity entity to merge
     */
    public void merge(T entity);

    /**
     * remove a entity
     * @param entity entity to remove
     */
    public void remove(T entity);

    /**
     * remove a entity by identiy
     * @param id identity
     */
    public void removeById(ID id);

    /**
     * romove a list of entities
     * @param entities entity list
     */
    public void removeAll(List<T> entities);

    /**
     * find the matched entity list by condition
     * @param criteria search condition
     * @return matched entity list
     */
    public List<T> findByCriteria(DetachedCriteria criteria);

    /**
     * find the paged entity list by condition
     * @param criteria search condition
     * @param pageInfo page information
     * @return
     */
    public PageInfo findPageByCriteria(DetachedCriteria criteria,
            int startIndexI, int pageSize);
}